var currentPage = 1;
loadMyEssay();

function loadMyEssay() {

	$(document).ready(function() {
		init(currentPage);
	});

	function init(pageNo) {
		$("#thislist").html("");
		$.ajax({
			url: urlcore + "/api/shopInfo/selectShopList?status=" + 0 + "&current=" + pageNo,
			type: "get",
			dataType: 'json',
			async: false,
			contentType: "application/json;charset=utf-8",
			success: function(data) {

				if(data.success == true) {
					$.each(data.data.list, function(i, n) {
					  
					    var img=n.headImg==null?'http://app.jiagangwangluo.com/api//ATTACHMENT/cab06117-6607-401a-843d-5ac103323fb6/sqz.png':n.headImg;
						var storeName=n.storeName==null?'暂无':n.storeName;
						var sortName=n.sortType==null?'暂无':n.sortType.sortName;
						var shopDeposit=n.shopDeposit==null?'0':n.shopDeposit;
						var bondMoney=n.bondMoney==null?'0':n.bondMoney;
						var thislist =
						'<li class="clearfix">'+
				        	'<div class="pull-left sh-img"><img src="'+img+'"></div>'+
				            '<div class="pull-left sh-center">'+
				            	'<div class="sh-tt">'+storeName+'</div>'+
				                '<div class="sh-txt">分类: '+sortName+'</div>'+
				                '<div class="sh-txt">押金: '+shopDeposit+' 元</div>'+
				                '<div class="sh-txt">保证金: '+bondMoney+' 元</div>'+
				             '</div>'+
				             '<div class="pull-right">'+
				            	'<a href="javascript:confirmShopStatus('+n.id+','+1+');" class="btn btn-sh">同意</a>'+
				               '<a href="javascript:confirmShopStatus('+n.id+','+2+');" class="btn btn-sh btn-sh-b">不同意</a>'+
				             '</div>	'+
	                    '</li>';
						$('#thislist').append(thislist);
					});
					$("#pager").pager({
						pagenumber: pageNo,
						pagecount: data.data.pages,
						totalcount: data.data.total,
						buttonClickCallback: PageClick
					});

				} else if(data.code == 'OVERTIME') {
					var thisUrl = window.location.href;
					alert(thisUrl);
					if(thisUrl.indexOf('login.html') <= -1) {
						top.window.location.href = "login.html";
					}

				} else {
					if(data.msg != '空数据') {
						alert(data.msg)
					} else {
						$('#thiscount').text(0);
					}
				}

			},
			error: function() {
				alert("error");
			}
		});
	}
	PageClick = function(pageclickednumber) {
		init(pageclickednumber);
	}
}

function confirmShopStatus(id, status) {
	if(status == 1) {
		if(confirm("您确定通过吗？")) {
			shopStatus(id, status);
			return true;
		} else {
			return false;
		}
	}

	if(status == 2) {
		if(confirm("您确定不通过吗？")) {
			shopStatus(id, status);
			return true;
		} else {
			return false;
		}
	}
	/*if(status == 2) {
		if(confirm("您确定删除吗？")) {
			shopStatus(id, status);
			return true;
		} else {
			return false;
		}
	}*/
}

//店铺存在状态
function shopStatus(id, status) {

	$.ajax({
		url: urlcore + "/api/shopInfo/update?id=" + id,
		type: "post",
		contentType: "application/json;charset=utf-8",
		data: JSON.stringify({
			"id": id,
			"status": status
		}),
		dataType: "json",
		success: function(data) {
			if(data.success == true) {
				//刷新
				location.reload();
			} else if(data.code == 'OVERTIME') {
				var thisUrl = window.location.href;
				if(thisUrl.indexOf('login.html') <= -1) {
					top.window.location.href = "login.html";
				}
			} else {
				alert(data.msg);
			}

		},
		error: function() {
			alert("error");
		}
	});
}
